package testmybatis.springmybatis;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import testmybatis.mapper.CompanyMapper;
import testmybatis.mapper.MemberMapper;

/**
 * @Description 模拟MapperScannerRegistrar
 * @Author dangxianyue
 * @Date 2024/3/27 21:40
 */
public class MyMapperScannerRegistrarV1 implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata, final BeanDefinitionRegistry registry, final BeanNameGenerator importBeanNameGenerator) {
        final AbstractBeanDefinition beanDefinition1 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        beanDefinition1.setBeanClass(MyMybatisFactoryBean.class);
        beanDefinition1.getConstructorArgumentValues().addGenericArgumentValue(MemberMapper.class);
        registry.registerBeanDefinition("memberMapper", beanDefinition1);

        final AbstractBeanDefinition beanDefinition2 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        beanDefinition2.setBeanClass(MyMybatisFactoryBean.class);
        beanDefinition2.getConstructorArgumentValues().addGenericArgumentValue(CompanyMapper.class);
        registry.registerBeanDefinition("companyMapper", beanDefinition2);
    }
}
